<?php
/**********************************************************
Copyright (c) 2011 Wayne State University Library System
Licensed under the MIT License.
Redistributions of files must retain the above copyright notice.

This software is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

MapIt!
http://www.lib.wayne.edu/MapIt!/
http://code.google.com/XXXX
contact: Paul Gallagher, Developer Librarian WSULS
email: paul.gallagher@wayne.edu
***********************************************************/
require_once('admin/config/config.inc.php');
require_once('MDB2.php');


//#####################  Functions #############################
function CreateOptionBox($dsn)	
{
	// create MDB2 instance
	$mdb2 = MDB2::factory($dsn);
	$mdb2->setFetchMode(MDB2_FETCHMODE_ASSOC);
	$query = 'SELECT DISTINCT location_code, location_name FROM locations WHERE content_type = "call_number"';
	$result = $mdb2->query($query);
	$array = $result->fetchAll();
	$result->free();

	if ($debug == true) {
		print_r($array);
	}

	//Create option box value from each subarray
	foreach($array as $subarray)	{
		foreach($subarray as $key => $data)	{
		//Check the id, provide the output tag
			switch($key)	{
				case ($key == 'location_code'):
					$opt .= '<option value="' . $data . '">'; 
				break;
				
				case ($key == 'location_name'):
					$opt .= $data . '</option>';
				break;
			}
		}
	}		
	return ('<select name="location" id="location">' . $opt . '</select>');
}



//#####################  Display Code #############################
$output = '<h2>Find an item by call number</h2>
			<form enctype="multipart/form-data" action="index.php" id="maps" method="get" class="noprint">
              <p>
                <label for="mapCode" class="required">Select a location: </label>';
$output .=	CreateOptionBox($dsn);
$output .=   '</p>
              <p>
                <label for="call_number" class="required">Enter a call number:</label>
                <input name="call" type="text" id="call" value="" size="22" maxlength="60" />
                <input type="submit" id="Submit" value="Search" />
              </p>
            </form>';

include('templates/main.php');